#include <fstream>
#include "glut/glut.h"

#include "rEngine.h"
#include "rTextType.h"

rEngine eng;
rTextType rTT;

void Init()
{
	glClearColor(0.2,0.2,0.2,1.0);

	rTT.LoadFont("fonts//ProFontWindows.ttf");
	eng.RegisterType(static_cast<IItemType*>(&rTT));

	std::fstream* f = new std::fstream("test.txt",std::ios::binary|std::ios::in|std::ios::out);
	eng.OpenStream(f);
	
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void Render(void)
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	eng.Render();

	glutSwapBuffers();
	glFlush();
}

void Update(void)
{

}

void Resize(int width, int height)
{
	glViewport(0,0,width,height); 
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluOrtho2D(0,width,height,0);
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
}


int main(int argc, char ** args)
{
	glutInit(&argc, args);
	glutCreateWindow("Red");

	glutReshapeFunc(Resize);
	glutDisplayFunc(Render);
	glutIdleFunc(Update);

	Init();

	glutMainLoop();

}
